package com.web_bloks.widget.client;

import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.ui.HTML;

import com.web_bloks.user.client.UserMessageServer;
/**
 * 
 * @author Jean-Lou Dupont
 *
 */
public class UserMessageWidget extends HTML 
	implements UserMessageServer {

	Timer timer = null;
	
	final static int DEFAULT_TIMEOUT = 10000;

	public UserMessageWidget(String msg) {
		super();
		setHTML( msg );
	}
	
	public UserMessageWidget() {
		super();
	}
	
	public void sendMessage(String msg) {
		this.setHTML( msg );
		updateTimer();
	}
	
	public void clearMessage() {
		this.setHTML( "" );
	}
	protected void updateTimer() {

		if ( null != timer ) {
			timer.cancel();
			timer = null;
		}
		
		timer = new Timer() {
			public void run() {
				clearMessage();
			}
		};
		
		timer.schedule(DEFAULT_TIMEOUT);
	}
	
}//END